package com.bqtv.sport.ui.mine

import android.content.Context
import android.content.Intent
import android.view.View
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.commen.utils.glide.GlideApp
import com.bqtv.sport.databinding.ActivityMatchDateBinding
import com.bqtv.sport.databinding.ActivityPersonalProfileBinding
import com.bqtv.sport.dialog.SelectPicBottomDialog
import com.bqtv.sport.dialog.SetTextDialog
import com.bqtv.sport.ui.home.SearchActivity
import com.hjq.base.BaseActivity
import com.hjq.base.util.GlideEngine
import com.luck.picture.lib.basic.PictureSelector
import com.luck.picture.lib.config.SelectMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.interfaces.OnResultCallbackListener

class PersonalProfileActivity : AppActivity<ActivityPersonalProfileBinding>() {
    companion object {
        fun start(context: Context) {
            val intent = Intent(context, PersonalProfileActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding() = ActivityPersonalProfileBinding.inflate(layoutInflater)

    override fun initView() {

    }

    override fun initData() {


        initListener()
    }

    private fun initListener() {

        binding.llAvatar.setOnClickListener(this)
        binding.llNickname.setOnClickListener(this)
        binding.llSignature.setOnClickListener(this)
        binding.llQrCode.setOnClickListener(this)
        binding.llSetPayPsw.setOnClickListener(this)
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when(view){
            binding.llAvatar -> {
//                val picDialog = SelectPicBottomDialog.Builder(getContext())
//                picDialog.clickResult = object : SelectPicBottomDialog.Builder.ClickResult {
//                    override fun onPhotoClick() {
//
//                    }
//
//                    override fun onAlbumClick() {
//
//                    }
//
//
//                }
//                picDialog.show()
                //头像
                PictureSelector.create(getContext())
                    .openGallery(SelectMimeType.ofImage())
                    .setImageEngine(GlideEngine.createGlideEngine())
                    .isDisplayCamera(true)
                    .setMaxSelectNum(1)
                    .forResult(object : OnResultCallbackListener<LocalMedia> {
                        override fun onResult(result: ArrayList<LocalMedia>) {
                            // 1.media.getPath(); 为原图path
                            // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true  注意：音视频除外
                            // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true  注意：音视频除外
                            // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的
                            if (result.size == 0)
                                return
                            GlideApp.with(getContext())
                                .load(result[0].getPath())
                                .into(binding.ivAvatar)
//                                    upDataHead(result[0].realPath, result[0].getFileName());
                        }

                        override fun onCancel() {}
                    })
            }
            binding.llSetPayPsw -> {
                SetPayPswActivity.start(getContext())
            }
            binding.llNickname -> {
                val nameDialog = SetTextDialog.Builder(getContext())
                nameDialog.clickResult = object : SetTextDialog.Builder.ClickResult {
                    override fun onconfirmClick(text: String) {
                        
                    }
                }
                nameDialog.show()
            }
        }
    }
}